<template>
  <div class="ai-portal-mobile app-background">
    <!-- 头部区域 -->
    <header class="header">
      <div class="logo-area">
        <img src="@/assets/images/logo.png" alt="西安建筑科技大学校徽" class="logo" />
        <div class="title-container">
          <h1 class="title">西安建筑科技大学</h1>
          <h2 class="subtitle">AI智能门户</h2>
        </div>
      </div>
      <p class="greeting">你好，欢迎使用AI助手</p>
    </header>

    <!-- 内容容器 -->
    <div class="content-container">
      <!-- 核心功能区域 -->
      <section class="section">
        <h2 class="section-title">核心功能</h2>
        <p class="section-desc">高效解决学习工作中的实际问题</p>
        <div class="feature-grid">
          <div
            class="feature-item"
            v-for="feature in features"
            :key="feature.title"
            @click="handleFeatureClick(feature)"
          >
            <div class="feature-icon-container">
              <div class="feature-icon-emoji">{{ feature.icon }}</div>
            </div>
            <h3 class="feature-title">{{ feature.title }}</h3>
            <p class="feature-desc">{{ feature.desc }}</p>
          </div>
        </div>
      </section>

      <!-- 空状态区域 -->
      <section class="section empty-state-section">
        <div class="empty-state-card">
          <div class="empty-state-icon">
            <i class="robot-icon"></i>
          </div>
          <div class="empty-state-content">
            <h3 class="empty-title">智能体正在待命</h3>
            <p class="empty-desc">选择一个功能开始对话，或探索更多智能服务</p>
            <ul class="ai-tips">
              <li>• 智能体可解答专业领域问题</li>
              <li>• 支持多轮对话与上下文理解</li>
              <li>• 可生成结构化报告与分析</li>
            </ul>
          </div>
        </div>
      </section>
    </div>

    <!-- 底部导航栏 -->
    <footer class="chat-list-footer">
      <div class="nav-item" :class="{ active: $route.name === 'index' }" @click="navigateTo('/')">
        <i class="nav-icon home-icon"></i>
        <span>首页</span>
      </div>
      <div class="nav-item" :class="{ active: $route.name === 'home' || $route.name === 'mobiles' }" @click="navigateTo('/mobiles')">
        <i class="nav-icon message-icon"></i>
        <span>对话</span>
      </div>
      <div class="nav-item" :class="{ active: $route.name === 'discover' }" @click="navigateTo('/discover')">
        <i class="nav-icon discover-icon"></i>
        <span>发现</span>
      </div>
    </footer>
  </div>
</template>

<script>
import { streamFetch, SseResponseEventEnum } from '@/utils/streamFetch.js';
import { getToken } from '@/utils/auth.js';
import { generateSecureRandomString } from '@/utils/crypto.js';

export default {
  name: 'IndexView',
  data() {
    return {
      features: [
        {
          title: "deepseek",
          desc: "深度思考与复杂问题解答专家",
          icon: "🤖",
          appId: 46128
        },
        {
          title: "通用对话",
          desc: "日常交流与基础问题解答助手",
          icon: "💬",
          appId: 46121
        },
        {
          title: "文案撰写",
          desc: "专业文案创作与优化专家",
          icon: "✏️",
          appId: 46579
        },
        {
          title: "简历制作",
          desc: "专业简历模板与个性化制作指导",
          icon: "📄",
          appId: 46582
        },
        {
          title: "方案策划",
          desc: "快速生成各类活动与工作方案",
          icon: "📝",
          appId: 46125
        },
        {
          title: "教学设计",
          desc: "教学方案与课程设计助手显",
          icon: "📚",
          appId: 46556
        },
      ],
      quickActions: [
        {
          title: "开始新对话",
          icon: "💬",
          action: "newChat"
        },
        {
          title: "查看历史",
          icon: "🕒",
          action: "history"
        },
        {
          title: "探索智能体",
          icon: "🔍",
          action: "discover"
        },
        {
          title: "帮助中心",
          icon: "❓",
          action: "help"
        }
      ]
    };
  },

  mounted() {
  console.log('IndexView mounted');
},

  methods: {
    navigateTo(path) {
      this.$router.push(path);
    },

    async handleFeatureClick(feature) {
      console.log('点击了功能:', feature.title);

      if (feature.appId) {
        this.$router.push({
          name: 'discover',
          query: { appId: feature.appId }
        });
      }
    },

    handleQuickAction(action) {
      switch(action.action) {
        case 'newChat':
          // 跳转到对话页面
          this.$router.push('/mobiles');
          break;
        case 'history':
          // 跳转到历史记录
          this.$router.push('/mobiles');
          break;
        case 'discover':
          // 跳转到发现页面
          this.$router.push('/discover');
          break;
        case 'help':
          // 显示帮助信息
          alert('帮助中心功能正在开发中');
          break;
      }
    },

    getIconFromName(name) {
      const iconMap = {
        '校园': '🎓',
        '宿舍': '🛏️',
        '课程': '📅',
        '图书馆': '📚',
        '成绩': '📈',
        '制度': '📜',
        '出题': '✏️',
        '助手': '🤖',
        '查询': '🔍',
        '文案': '✏️',
        '简历': '📄',
        '方案': '📝',
        '教学': '📚',
        'deepseek': '🤖',
        '通用': '💬'
      };

      for (const [key, icon] of Object.entries(iconMap)) {
        if (name.includes(key)) {
          return icon;
        }
      }

      return '🤖';
    },

    created() {
      this.features = this.features.map(feature => ({
        ...feature,
        icon: this.getIconFromName(feature.title)
      }));
    }
  }
};
</script>

<style scoped>
.ai-portal-mobile {
  font-family: "PingFang SC", "Microsoft YaHei", -apple-system, BlinkMacSystemFont, sans-serif;
  padding: 0;
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  /* background: linear-gradient(135deg, #f5f7fa 0%, #e4edf9 100%); 保持背景渐变 */
  background-image: url('@/assets/images/background.png'); /* 添加背景图 */
  background-size: cover; /* 让图片铺满容器 */
  background-position: center; /* 居中显示 */
  background-repeat: no-repeat; /* 不重复 */
}

/* 只需要修改这部分样式 */
.header {
  text-align: center;
  padding: 24px 16px 12px;
  flex-shrink: 0;
  /* 移除背景色和圆角，使其与整体背景融为一体 */
  background: transparent;
  border-radius: 0;
  box-shadow: none;
}


.logo-area {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

.logo {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  margin-right: 16px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 3px solid #fff;
}

.title-container {
  text-align: left;
}

.title {
  font-size: 22px;
  font-weight: 600;
  color: #202124;
  margin: 0 0 4px 0;
  letter-spacing: 0.5px;
}

.subtitle {
  font-size: 16px;
  font-weight: 500;
  color: #4285f4;
  margin: 0;
}

.greeting {
  font-size: 16px;
  color: #5f6368;
  margin: 12px 0 0;
  font-weight: 500;
}

.content-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
  /* 移除背景色，让渐变背景显示出来 */
}

/* 修改section样式，移除白色背景和边框 */
.section {
  margin-bottom: 28px;
  /* 移除背景色和边框 */
  border-radius: 16px;
  padding: 20px;
  /* 添加透明背景 */
  background: transparent;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
  color: #202124;
  display: flex;
  align-items: center;
  position: relative;
  padding-left: 12px;
}

.section-title::before {
  content: '';
  width: 4px;
  height: 18px;
  background: linear-gradient(to bottom, #4285f4, #34a853);
  border-radius: 2px;
  margin-right: 8px;
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
}

.section-desc {
  font-size: 14px;
  color: #5f6368;
  margin-bottom: 20px;
  padding-left: 12px;
}

.feature-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.feature-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px;
  border-radius: 14px;
  background: #f8f9fa;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid #f1f3f4;
}

.feature-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 16px rgba(66, 133, 244, 0.15);
  background: #ffffff;
  border-color: #e3f2fd;
}

.feature-icon-container {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  box-shadow: 0 4px 8px rgba(66, 133, 244, 0.2);
}

.feature-icon-emoji {
  font-size: 28px;
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.feature-title {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
  color: #202124;
  text-align: center;
  line-height: 1.3;
}

.feature-desc {
  font-size: 12px;
  color: #5f6368;
  text-align: center;
  line-height: 1.4;
  flex-grow: 1;
  display: flex;
  align-items: center;
}

/* 快速开始区域样式 */
.quick-start {
  background: linear-gradient(135deg, #e8f0fe 0%, #d2e3fc 100%);
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.quick-action-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  border-radius: 12px;
  background: white;
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid #e8eaed;
}

.quick-action-item:hover {
  transform: translateY(-3px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  background: #f8f9fa;
}

.action-icon {
  font-size: 20px;
  margin-bottom: 8px;
}

.action-text {
  font-size: 12px;
  color: #202124;
  text-align: center;
  font-weight: 500;
}

.empty-state-section {
  background: transparent;
}

.empty-state-card {
  background: white;
  border-radius: 16px;
  padding: 28px 20px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  border: 1px solid #f1f3f4;
}

.empty-state-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e3f2fd 0%, #bbdefb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
  box-shadow: 0 4px 12px rgba(66, 133, 244, 0.2);
}

.robot-icon {
  width: 36px;
  height: 36px;
  position: relative;
}

.robot-icon::before {
  content: '';
  position: absolute;
  width: 28px;
  height: 28px;
  border: 2px solid #4285f4;
  border-radius: 50%;
  top: 0;
  left: 0;
}

.robot-icon::after {
  content: '';
  position: absolute;
  width: 20px;
  height: 18px;
  border: 2px solid #4285f4;
  border-radius: 4px;
  bottom: 0;
  left: 4px;
}

.empty-title {
  font-size: 18px;
  font-weight: 600;
  color: #202124;
  margin: 0 0 12px 0;
}

.empty-desc {
  font-size: 14px;
  color: #5f6368;
  margin: 0 0 20px 0;
  max-width: 280px;
  line-height: 1.5;
}

.ai-tips {
  list-style: none;
  padding: 0;
  margin: 0;
  text-align: left;
  width: 100%;
  max-width: 280px;
}

.ai-tips li {
  font-size: 13px;
  color: #5f6368;
  margin-bottom: 10px;
  line-height: 1.4;
  position: relative;
  padding-left: 16px;
}

.ai-tips li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #4285f4;
}

.ai-tips li:last-child {
  margin-bottom: 0;
}

.chat-list-footer {
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 4px 0;
  border-top: 1px solid #eee;
  background-color: #fff;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 100;
  height: 56px; /* 固定高度 */
  box-sizing: border-box;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  cursor: pointer;
  padding: 2px 0;
  font-style: normal;
  width: 33.333%;
}

.nav-item:hover {
  transform: scale(1.05);
}

.nav-icon {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  color: #5f6368;
  font-size: 20px;
}

.nav-item.active .nav-icon,
.nav-item.active span {
  color: #4285f4;
  font-style: normal;
  font-weight: 600;
}

.nav-item span {
  font-size: 12px;
  color: #5f6368;
  margin-top: 4px;
  font-style: normal;
  font-weight: 500;
}

/* 首页图标 - 简洁房屋线条 */
.home-icon::before {
  content: '';
  position: absolute;
  width: 0;
  height: 0;
  border-left: 8px solid transparent;
  border-right: 8px solid transparent;
  border-bottom: 8px solid currentColor;
  top: -4px;
}

.home-icon::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 12px;
  border: 2px solid currentColor;
  top: 4px;
}

/* 对话图标 - 简洁气泡线条 */
.message-icon::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 14px;
  border: 2px solid currentColor;
  border-radius: 12px 12px 12px 0;
}

.message-icon::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  border: 2px solid currentColor;
  border-top: none;
  border-left: none;
  transform: rotate(45deg);
  bottom: -2px;
  right: 2px;
}

/* 发现图标 - 简洁放大镜线条 */
.discover-icon::before {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-radius: 50%;
  top: 2px;
  left: 2px;
}

.discover-icon::after {
  content: '';
  position: absolute;
  width: 8px;
  height: 2px;
  background-color: currentColor;
  transform: rotate(45deg);
  bottom: 6px;
  right: 2px;
}

/* 移动端适配 */
@media (max-width: 480px) {
  .chat-list-footer {
    padding: 4px 0;
    height: 56px;
  }

  .nav-item span {
    font-size: 12px;
  }

  .nav-icon {
    font-size: 20px;
  }
}

/* 移动端适配 */
@media (max-width: 480px) {
  .ai-portal-mobile {
    padding: 0;
  }

  @media (max-width: 480px) {
  .header {
    padding: 14px 16px 16px;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
  }
}

  .logo {
    width: 60px;
    height: 60px;
  }

  .title {
    font-size: 20px;
  }

  .subtitle {
    font-size: 15px;
  }

  .greeting {
    font-size: 10px;
  }

  .content-container {
    padding: 0 12px 12px;
  }

  .section {
    padding: 16px;
    margin-bottom: 20px;
  }

  .section-title {
    font-size: 17px;
  }

  .feature-grid {
    gap: 12px;
  }

  /* 修改功能项的样式，添加半透明背景 */
.feature-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px;
  border-radius: 14px;
  /* 使用半透明背景色 */
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: all 0.3s ease;
  border: 1px solid rgba(241, 243, 244, 0.7);
}

  .feature-icon-container {
    width: 50px;
    height: 50px;
    margin-bottom: 10px;
  }

  .feature-icon-emoji {
    font-size: 24px;
  }

  .feature-title {
    font-size: 13px;
  }

  .feature-desc {
    font-size: 11px;
  }

  .quick-actions {
    gap: 10px;
  }

  .quick-action-item {
    padding: 10px 6px;
  }

  .action-icon {
    font-size: 18px;
    margin-bottom: 6px;
  }

  .action-text {
    font-size: 11px;
  }

  .empty-state-card {
    padding: 24px 16px;
  }

  .empty-state-icon {
    width: 64px;
    height: 64px;
  }

  .robot-icon {
    width: 32px;
    height: 32px;
  }

  .empty-title {
    font-size: 16px;
  }

  .empty-desc {
    font-size: 13px;
  }

  .ai-tips li {
    font-size: 12px;
  }
}
</style>
